package tutor;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Screen;

/**
 *
 * @author y_plaksyuk
 */
public abstract class AbstractUnit implements CommandListener {

	protected final TutorApp app;

	protected AbstractUnit(TutorApp app) {
		this.app = app;
	}

	public abstract String getTitle();

	public abstract Screen getScreen();

	public void start() {
		Screen screen = getScreen();
		screen.setCommandListener(this);
		app.switchDisplayable(null, screen);
	}

	public void stop() {
		app.switchDisplayable(null, app.getMainScreen());
	}

	protected void handleCommand(Command command) {
		if (command == app.getCancelCommand())
			stop();
	}

	public final void commandAction(Command c, Displayable d) {
		handleCommand(c);
	}
}
